﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using 纺织贸易管理系统;

namespace 后整理管理系统.其他窗体
{
    public partial class 修改信息 : Form
    {
        private List<JuanHaoTable> rolls=new List<JuanHaoTable>();
        public 修改信息(List<JuanHaoTable> juanHaoTables)
        {
            InitializeComponent();
            this.rolls = juanHaoTables;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(textBox1.Text.Trim()))
            {
                MessageBox.Show("请输入要修改的内容");
                return;
            }
            if (comboBox1.SelectedIndex == -1)
            {
                MessageBox.Show("请选择要修改的项目");
                return;
            }
            switch (comboBox1.Text)
            {
                case "颜色":
                    foreach (var item in rolls)
                    {
                        item.yanse = textBox1.Text.Trim();
                    }
                    break;
                case "品名":
                    foreach (var item in rolls)
                    {
                        item.SampleName = textBox1.Text.Trim();
                    }
                    break;
                case "工艺":
                    foreach (var item in rolls)
                    {
                        item.Houzhengli = textBox1.Text.Trim();
                    }
                    break;
                case "缸号":
                    foreach (var item in rolls)
                    {
                        item.GangHao = textBox1.Text.Trim();
                    }
                    break;
            }
            try
            {
                using (var trans = Connect.dbcontext.UseTran())
                {
                    Connect.dbcontext.Updateable(rolls).ExecuteCommand();
                    trans.CommitTran();
                    MessageBox.Show("修改成功");
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
        }
    }
}
